<?php
define ("LEGEND","false");
define ("EXPORTING","false");
define ("S_NAME","");
define ("X_TYPE","datetime");
define ("Y_TIT","");
define ("CHART_TYPE","spline");
define ("SLEEP_TIME", "60000"); // c'est pour le graphe, il execute la requete chaque 1 minute
function echoEvent($json){
	$content="events: {
            load: function() {
               var series = this.series[0];
               setInterval(function() {
                  var x = (new Date()).getTime();";
	$content.=$json;
    $content.="}, ".SLEEP_TIME.");
            }
         }";
		 return $content;
}

function echoChart($render_to, $title, $json, $y, $serie_name){
	$content="";
	$content.="Highcharts.setOptions({
			   global: {
				  useUTC: false
			   }
			});
			var chart;
			$(document).ready(function() {
			   chart = new Highcharts.Chart({
				  chart: {
					 renderTo: '$render_to',
					 defaultSeriesType: '".CHART_TYPE."',
					 ";
	$content.=	echoEvent($json);
    $content.=" },
				 title: {
					 text: '$title'
				  },
			  xAxis: {
				 type: '".X_TYPE."',
				 tickPixelInterval: 120
			  },
			  yAxis: {
				 title: {
					text: '".Y_TIT."'
				 },
				 plotLines: [{
					value: 0,
					width: 1,
					color: '#808080'
				 }]
			  },
			  tooltip: {
				 formatter: function() {
						   return  Highcharts.dateFormat('%H:%M:%S', this.x) +'<br/>Total:'+ 
					   Highcharts.numberFormat(this.y, 0);
				 }
			  },
			  legend: {
				 enabled: ".LEGEND."
			  },
			  exporting: {
				 enabled: ".EXPORTING."
			  },
			  series: [{
				 name: '$serie_name',
				 data: (function() {
					// generate an array of random data
					var data = [],
					   time = (new Date()).getTime(),
					   i;
					for (i = -10; i <= 0; i++) {
					   data.push({
						  x: time + i * 1000,
						  y: $y
					   });
					}
					return data;
				 })()
			  }]
		   });
		});";
	return $content;
}
?>